home *** CD-ROM | disk | FTP | other *** search
- head 1.5;
- branch ;
- access ;
- symbols ;
- locks ; strict;
- comment @ * @;
-
-
- 1.5
- date 89.06.15.22.45.23; author douglis; state Exp;
- branches ;
- next 1.4;
-
- 1.4
- date 89.01.13.11.44.32; author douglis; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 88.09.22.22.12.10; author douglis; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 88.09.13.16.49.35; author douglis; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.08.14.15.08.51; author douglis; state Exp;
- branches ;
- next ;
-
-
- desc
- @Procedure to open and lock a database file, get a record, and close it
- again.
- @
-
-
- 1.5
- log
- @create database file if not already there
- @
- text
- @/*
- * Db_ReadEntry.c --
- *
- * Source code for the Db_ReadEntry procedure.
- *
- * Copyright 1988 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /sprite/src/lib/c/db/RCS/Db_ReadEntry.c,v 1.4 89/01/13 11:44:32 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
- #endif not lint
-
-
- #include <db.h>
- #include "dbInt.h"
-
-
- /*
- *----------------------------------------------------------------------
- *
- * Db_ReadEntry --
- *
- * Read a buffer from a specified location in the shared database.
- * This opens and locks the file, reads the data, and closes the
- * file. The lock is polled if necessary.
- *
- * Results:
- * -1 indicates an error, in which case errno indicates more details.
- * 0 indicates success.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
- int
- Db_ReadEntry(file, buffer, index, size, lockHow)
- char *file;
- char *buffer;
- int index;
- int size;
- Db_LockHow lockHow;
- {
- int status;
- int offset;
- int streamID;
- int bytesRead;
- Db_Handle handle;
-
- streamID = open(file, O_RDONLY | O_CREAT, FILE_MODE);
- if (streamID == -1) {
- syslog(LOG_ERR, "Db_ReadEntry: error opening file %s: %s.\n", file,
- strerror(errno));
- return(streamID);
- }
-
- offset = index * size;
- status = lseek(streamID, (long) offset, L_SET);
- if (status == -1) {
- return(status);
- }
- /*
- * Fake a Db_Handle for DbLockDesc.
- */
- handle.streamID = streamID;
- handle.lockHow = lockHow;
- handle.lockType = LOCK_SH;
- #ifndef CLEAN
- handle.fileName = file;
- #endif /* CLEAN */
- status = DbLockDesc(&handle);
- if (status == -1) {
- return(status);
- }
-
- bytesRead = read(streamID, buffer, size);
- if (bytesRead == -1) {
- status = -1;
- } else if (bytesRead != size) {
- status = -1;
- errno = 0;
- } else {
- status = 0;
- }
- (void) flock(streamID, LOCK_SH | LOCK_UN);
- (void) close(streamID);
-
- return(status);
- }
- @
-
-
- 1.4
- log
- @changed for buffering and for new arg passing to lock routine.
- [generic checkin msg].
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/db/RCS/Db_ReadEntry.c,v 1.3 88/09/22 22:12:10 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
- d58 1
- a58 1
- streamID = open(file, O_RDONLY, 0);
- d60 2
- @
-
-
- 1.3
- log
- @Changed some arg. orders, var. names, and Db_LockDesc to DbLockDesc.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: Db_ReadEntry.c,v 1.2 88/09/13 16:49:35 douglis Exp $ SPRITE (Berkeley)";
- d56 1
- d68 10
- a77 1
- status = DbLockDesc(streamID, LOCK_SH, lockHow);
- @
-
-
- 1.2
- log
- @fixed some lint.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: Db_ReadEntry.c,v 1.1 88/08/14 15:08:51 douglis Exp $ SPRITE (Berkeley)";
- d45 1
- a45 1
- Db_ReadEntry(file, index, bufSize, buf, lockHow)
- d47 1
- d49 1
- a49 2
- int bufSize;
- char *buf;
- d62 1
- a62 1
- offset = index * bufSize;
- d67 1
- a67 1
- status = Db_LockDesc(streamID, LOCK_SH, lockHow);
- d72 1
- a72 1
- bytesRead = read(streamID, buf, bufSize);
- d75 1
- a75 1
- } else if (bytesRead != bufSize) {
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
- d63 1
- a63 1
- status = lseek(streamID, offset, L_SET);
- @
-